package com.keyancompany.zhongbaopingtai.fragment;


import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.TextView;

import com.keyancompany.zhongbaopingtai.ConstansUrl;
import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.activity.BanlanceActivity;
import com.keyancompany.zhongbaopingtai.activity.CollectionActivity;
import com.keyancompany.zhongbaopingtai.activity.ComplaintActivity;
import com.keyancompany.zhongbaopingtai.activity.FriendsActivity;
import com.keyancompany.zhongbaopingtai.activity.MyCircleActivity;
import com.keyancompany.zhongbaopingtai.activity.MyTeamActivity;
import com.keyancompany.zhongbaopingtai.activity.PublishPackageActivity;
import com.keyancompany.zhongbaopingtai.activity.UserInforActivity;
import com.keyancompany.zhongbaopingtai.adapter.MineMenuAdapter;
import com.keyancompany.zhongbaopingtai.api.UserAPI;
import com.keyancompany.zhongbaopingtai.model.User;
import com.keyancompany.zhongbaopingtai.utils.IntentUtils;
import com.keyancompany.zhongbaopingtai.weight.CircleImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

import butterknife.Bind;
import butterknife.OnClick;
import butterknife.OnItemClick;

/**
 * Created by firefox on 2016/5/31.
 */
public class MineFragment extends BaseFragment {

    @Bind(R.id.avatar)
    CircleImageView avatar;
    @Bind(R.id.username)
    TextView username;
    @Bind(R.id.rating)
    TextView rating;
    @Bind(R.id.integrity)
    TextView integrity;
    @Bind(R.id.balance)
    TextView balance;
    @Bind(R.id.not_pay_balance)
    TextView notPayBalance;
    @Bind(R.id.mine_menu_grid)
    GridView mineMenuGrid;

    @Override
    public int getContentViewId() {
        return R.layout.fragment_mine;
    }

    @Override
    public void setUpViews() {

        mineMenuGrid.setAdapter(new MineMenuAdapter(context));
        updateData();
    }

    public void updateData() {
        if (getActivity() == null)
            return;
        User user = UserAPI.getCurrentUser();
        username.setText(user.getUsername());
        balance.setText((TextUtils.isEmpty(user.getAbleMoney()) ? "0" : user.getAbleMoney()) + "\n" + getString(R.string.abel_money_text));
        notPayBalance.setText((TextUtils.isEmpty(user.getUnableMoney()) ? "0" : user.getUnableMoney()) + "\n" + getString(R.string.on_pay_money_text));
        rating.setText(getString(R.string.rating_text, user.getRate() + ""));

        ImageLoader.getInstance().displayImage(user.getHeadpic(), avatar);
    }

    @OnClick(R.id.avatar)
    public void toUserInfor(View view) {
        IntentUtils.startActivity(context, UserInforActivity.class);
    }

    @OnClick({R.id.not_pay_balance, R.id.balance})
    void toBanlance() {
        IntentUtils.startActivity(context, BanlanceActivity.class);
    }

    @OnItemClick(R.id.mine_menu_grid)
    void gridOnItem(AdapterView<?> parent, View view, int position, long id) {
        switch (position) {
            case 0: //我的项目
                IntentUtils.startActivity(context, PublishPackageActivity.class);
                break;
            case 1://我的收藏
                IntentUtils.startActivity(context, CollectionActivity.class);
                break;
            case 2: //我的申诉
                IntentUtils.startActivity(context, ComplaintActivity.class);
                break;
            case 3://我的团队
                IntentUtils.startActivity(context, MyTeamActivity.class);
                break;
            case 4: //我的圈子
                IntentUtils.startActivity(context, MyCircleActivity.class);
                break;
            case 5://我的好友
                IntentUtils.startActivity(context, FriendsActivity.class);
                break;
        }
    }

}
